/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * <p>Project: javaseapp - ListSort
 * <p>Powered by webrx On 2021-08-20 11:27:35
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class ListSort {
    public static void main(String[] args) {
        //此行生成的List为静态，不可以排序
        List<String> list1 = List.of("java", "c", "go", "python", "javascript");
        List<String> list2 = Arrays.asList("java", "c", "go", "python", "javascript");
        List<String> list = Arrays.asList("java,c,go,python,javascript".split(","));
        System.out.println(list);
        //降序 (a,b)->b.compareTo(a)
        list.sort(Comparator.reverseOrder());
        System.out.println(list);

        //升序 list.sort((a,b)->a.compareTo(b));
        list.sort(Comparator.naturalOrder());
        System.out.println(list);
        System.out.println("-----------------------------");
        //根据字母个数或长度进行排序
        list.sort(Comparator.comparingInt(String::length));
        System.out.println(list);//[c, go, java, python, javascript]
        list.sort((a, b) -> b.length() - a.length());
        System.out.println(list);//[javascript, python, java, go, c]

        //Collections.sort()
        //Arrays.sort()

    }
}
